/*================================================================
*   Copyright (C) 2019 Guangzhou Firefly Ltd. All rights reserved.
*   
*   文件名称：frog_maze.c
*   创 建 者：luhuadong
*   创建日期：2019年10月18日
*   描    述：
*
================================================================*/


#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
	if(argc < 2) {
	
		printf("Usage: ./frog_maze <file>\n\n");
		return -1;
	}

	/* Read maze from file */
	FILE *fp = fopen(argv[1], "r");

	if(!fp) {

		perror("Open file");
		return -1;
	}

	int n, m, P;
	int i, j;

	/* Read the first line to initialization n, m, P */
	fscanf(fp, "%d %d %d\n", &n, &m, &P);

	if(n < 1 || n > 10 || m < 3 || P < 1 || P > 100) {

		printf("Out of range\n");
		return -1;
	}

	printf(">> n=%d, m=%d, P=%d\n", n, m, P);

	/* Create maze */
	char maze[n][m];
	memset(maze, '0', n*m);

	/* Initialization maze */
	char line[100];

	for(i=0; i<n && !feof(fp); i++) {
	
		for(j=0; j<m; j++) {
		
			fscanf(fp, "%c ", &maze[i][j]);
		}
		fscanf(fp, "\n");
	}

	fclose(fp);

	/* Show the maze */
	for(i=0; i<n; i++) {
	
		for(j=0; j<m; j++) {
		
			printf("%c ", maze[i][j]);
		}
		printf("\n");
	}

	/* Go */
	

	return 0;
}
